package com.hsjk.szwj.module.train.controller.admin;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseDetailRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCoursePageReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCoursePageRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCreateCourseReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminMemberCoursePageReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminMemberCoursePageRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminPlatformCoursePageReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminPlatformCoursePageRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminUpdateCourseReqVO;
import com.hsjk.szwj.module.train.service.ICourseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/08/04 00:52
 **/
@Tag(name = "后台管理端 - 培训课程相关接口")
@RestController
@RequestMapping("/train/course")
@Validated
public class AdminCourseController {

    @Resource
    private ICourseService courseService;

    @PostMapping("/page-course")
    @Operation(summary = "获取课程分页列表")
    @PreAuthorize("@ss.hasPermission('train:course:query')")
    public CommonResult<PageResult<AdminCoursePageRespVO>> getAdminCoursePage(@RequestBody @Valid AdminCoursePageReqVO reqVO) {
        return success(courseService.getAdminCoursePage(reqVO));
    }

    @PostMapping("/page-platform-course")
    @Operation(summary = "获取平台课程分页列表")
    @PreAuthorize("@ss.hasPermission('train:course:query')")
    public CommonResult<PageResult<AdminPlatformCoursePageRespVO>> getAdminPlatformCoursePage(@RequestBody @Valid AdminPlatformCoursePageReqVO reqVO) {
        return success(courseService.getAdminPlatformCoursePage(reqVO));
    }

    @GetMapping("/get-course-by-id")
    @Operation(summary = "根据课程id获取课程详情")
    @PreAuthorize("@ss.hasPermission('train:course:query')")
    public CommonResult<AdminCourseDetailRespVO> getAdminCourseDetail(@RequestParam Long id) {
        return success(courseService.getAdminCourseDetail(id));
    }

    @PostMapping("/member-page-course")
    @Operation(summary = "用户课程信息分页列表")
    @PreAuthorize("@ss.hasPermission('train:course:query')")
    public CommonResult<PageResult<AdminMemberCoursePageRespVO>> memberCoursePage(@RequestBody @Valid AdminMemberCoursePageReqVO reqVO) {
        return success(courseService.memberCoursePage(reqVO));
    }

    @PostMapping("/create")
    @Operation(summary = "创建课程")
    @PreAuthorize("@ss.hasPermission('train:course:create')")
    public CommonResult<Boolean> createCourse(@RequestBody @Valid AdminCreateCourseReqVO reqVO) {
        return success(courseService.createCourse(reqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新课程")
    @PreAuthorize("@ss.hasPermission('train:course:update')")
    public CommonResult<Boolean> updateCourse(@RequestBody @Valid AdminUpdateCourseReqVO reqVO) {
        return success(courseService.updateCourse(reqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除课程")
    @PreAuthorize("@ss.hasPermission('train:course:delete')")
    public CommonResult<Boolean> deleteOfficialWebsite(@RequestParam("id") Long id) {
        courseService.deleteCourse(id);
        return success(true);
    }
}
